package com.example.lightenergypolymerize.util;

import com.example.lightenergypolymerize.entity.SecurityUserDetails;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityUtil {
    /**
     * 从springsecurity得到登录用户对象
     * @return
     */
    public static SecurityUserDetails getCurrentUser() {
        SecurityUserDetails userDetails = null;
        try{
            userDetails = (SecurityUserDetails)SecurityContextHolder.getContext()
                    .getAuthentication().getPrincipal();
        }catch (Exception e) {

        }
        return userDetails;
    }
}
